<?php
/**
* @version $Id: profilebox.php 897 2009-06-27 22:13:52Z mahagr $
* Kunena Component
* @package Kunena
*
* @Copyright (C) 2008 - 2009 Kunena Team All rights reserved
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
* @link http://www.kunena.com
*
* Based on FireBoard Component
* @Copyright (C) 2006 - 2007 Best Of Joomla All rights reserved
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
* @link http://www.bestofjoomla.com
*
* Based on Joomlaboard Component
* @copyright (C) 2000 - 2004 TSMF / Jan de Graaff / All Rights Reserved
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
* @author TSMF & Jan de Graaff
**/

// Dont allow direct linking
defined( '_JEXEC' ) or die('Restricted access');

$fbConfig =& CKunenaConfig::getInstance();
$kunena_my = &JFactory::getUser();
$kunena_db = &JFactory::getDBO();
//first we gather some information about this person
$kunena_db->setQuery("SELECT su.view, u.name, su.moderator, su.avatar FROM #__fb_users AS su"
                    . " LEFT JOIN #__users AS u on u.id=su.userid WHERE su.userid={$kunena_my->id}", 0, 1);

$_user = $kunena_db->loadObject();

$fbavatar = NULL;
if ($_user != NULL)
{
        $prefview = $_user->view;
        $username = $_user->name; // externally used  by fb_pathway, myprofile_menu
        $moderator = $_user->moderator;
        $fbavatar = $_user->avatar;
        $jr_username = $_user->name;
}

$jr_avatar = '';
if ($fbConfig->avatar_src == "jomsocial")
{
        // Get CUser object
        $jsuser =& CFactory::getUser($kunena_my->id);
    $jr_avatar = '<img src="' . $jsuser->getThumbAvatar() . '" alt=" " />';
}
else if ($fbConfig->avatar_src == "clexuspm")
{
    $jr_avatar = '<img src="' . MyPMSTools::getAvatarLinkWithID($kunena_my->id) . '" alt=" " />';
}
else if ($fbConfig->avatar_src == "cb")
{
        $jr_avatar = $kunenaProfile->showAvatar($kunena_my->id);
}
else if ($fbConfig->avatar_src == "aup") // integration AlphaUserPoints
{
        $api_AUP = JPATH_SITE.DS.'components'.DS.'com_alphauserpoints'.DS.'helper.php';
        if ( file_exists($api_AUP)) {
                ( $fbConfig->fb_profile=='aup' ) ? $showlink=1 : $showlink=0;
                $jr_avatar = AlphaUserPointsHelper::getAupAvatar( $kunena_my->id, $showlink, $fbConfig->avatarsmallwidth, $fbConfig->avatarsmallheight );
        } // end integration AlphaUserPointselse
}
else
{
    if ($fbavatar != "") {
                if(!file_exists(KUNENA_PATH_UPLOADED .DS. 'avatars/s_' . $fbavatar)) {
            $jr_avatar = '<img src="'.KUNENA_LIVEUPLOADEDPATH.'/avatars/' . $fbavatar . '" alt=" " style="max-width: '.$fbConfig->avatarsmallwidth.'px; max-height: '.$fbConfig->avatarsmallheight.'px;" />';
                } else {
                  $jr_avatar = '<img src="'.KUNENA_LIVEUPLOADEDPATH.'/avatars/s_' . $fbavatar . '" alt=" " />';
                }
    }
    else {
                 $jr_avatar = '<img src="'.KUNENA_LIVEUPLOADEDPATH.'/avatars/s_nophoto.jpg" alt=" " />';
        $jr_profilelink = '<a href="' . JRoute::_(KUNENA_LIVEURLREL . '&amp;func=myprofile') . '" >' . _PROFILEBOX_MYPROFILE . '</a>';
    }

}

if ($fbConfig->fb_profile == "cb" || $fbConfig->fb_profile == "jomsocial" || $fbConfig->fb_profile == "aup")
{
    $jr_profilelink = CKunenaLink::GetProfileLink($fbConfig, $kunena_my->id, _PROFILEBOX_MYPROFILE);
}
else if ($fbConfig->fb_profile == "clexuspm") {
    $jr_profilelink = '<a href="' . JRoute::_(KUNENA_LIVEURLREL . '&amp;func=myprofile') . '" >' . _PROFILEBOX_MYPROFILE . '</a>';
}
else
{
    $jr_profilelink = '<a href="' . JRoute::_(KUNENA_LIVEURLREL . '&amp;func=myprofile') . '" >' . _PROFILEBOX_MYPROFILE . '</a>';
}

$jr_myposts = '<a href="' . JRoute::_(KUNENA_LIVEURLREL .  '&amp;func=showauthor&amp;task=showmsg&amp;auth=' . $kunena_my->id . '') . '" >' . _PROFILEBOX_SHOW_MYPOSTS . '</a>';
$jr_latestpost = JRoute::_(KUNENA_LIVEURLREL . '&amp;func=latest');
?>

<?php // AFTER LOGIN AREA
if ($fbConfig->fb_profile == 'cb')
{
        $loginlink = CKunenaCBProfile::getLoginURL();
        $logoutlink = CKunenaCBProfile::getLogoutURL();
        $registerlink = CKunenaCBProfile::getRegisterURL();
        $lostpasslink = CKunenaCBProfile::getLostPasswordURL();
}
else if ($fbConfig->fb_profile == 'jomsocial')
{
        $loginlink = JRoute::_('index.php?option=com_community&amp;view=frontpage');
        $logoutlink = JRoute::_('index.php?option=com_community&amp;view=frontpage');
        $registerlink = JRoute::_('index.php?option=com_community&amp;view=register');
        $lostpasslink = JRoute::_('index.php?option=com_community&amp;view=frontpage');
}
else
{
        $loginlink = JRoute::_('index.php?option=com_user&amp;view=login');
        $logoutlink = JRoute::_('index.php?option=com_user&amp;view=login');
        $registerlink = JRoute::_('index.php?option=com_user&amp;view=register&amp;Itemid=' . $Itemid);
        $lostpasslink = JRoute::_('index.php?option=com_user&amp;view=reset&amp;Itemid=' . $Itemid);
        $lostuserlink = JRoute::_('index.php?option=com_user&amp;view=remind&amp;Itemid=' . $Itemid);
        $ruleslink = JRoute::_('index.php?option=com_kunena&Itemid=2&func=rules'); // Link to forum rules
        $helplink = JRoute::_('index.php?option=com_kunena&Itemid=2&func=faq');  // Link to forum help page
}

$type         = KunenaLogin::getType();
$return        = KunenaLogin::getReturnURL($type);

class KunenaLogin
{
        function getReturnURL($type)
        {
                if($itemid = '')
                {
                        $menu =& JSite::getMenu();
                        $item = $menu->getItem($itemid);
                        $url = JRoute::_($item->link.'&Itemid='.$itemid, false);
                }
                else
                {
                        // stay on the same page
                        $uri = JFactory::getURI();
                        $url = $uri->toString(array('path', 'query', 'fragment'));
                }

                return base64_encode($url);
        }

        function getType()
        {
                $user = & JFactory::getUser();
                return (!$user->get('guest')) ? 'logout' : 'login';
        }
}

?>
